'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ManageTbapplyCtrl
 * @description
 * # ManageTbapplyCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('ManageTbapplyCtrl', function ($scope, openApi, Util, $location, $rootScope, $routeParams, FormSubmit) {
        var id = $scope.process_id = $routeParams.id
        $scope.param = {};
        $scope.getTbType = function () {
            var param = {};
            param.type = "投标方式";
            Util.getKeyValue(param, function (data) {
                $scope.tbwaylist = data.data
            })
        };
        $scope.getZZType = function () {
            var param = {};
            param.type = "资质类别";
            Util.getKeyValue(param, function (data) {
                $scope.zztypelist = data.data
            })
        };
        $scope.showprojectTypeObj = function () {
            var param = {};
            param.type = "工程类型";
            Util.getKeyValue(param, function (data) {
                $scope.projectTypelist = data.data
            })
        };
        $scope.choosePeople = function () {
            var relModuleObj = {
                name: "ManageTbapplyCtrl",
                selectTab: "select_customer",
                selectTabContent: "合作伙伴"
            };
            // 清掉关联的编号
            Util.savaParamForReview($scope.param, id);
            Util.savaDataforsearch(relModuleObj);
            $location.path("finance/choosepeople")
        }
        $scope.submit = function (operationId) {

            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.bidApply;
            options.param = angular.copy($scope.param, {});
            options.param.projectType = $scope.param.projectTypeArr.toString();
            options.param.qualityReq = $scope.param.qualityReqArr.toString();
            FormSubmit.submit(options, $scope);
        };
        $scope.validate = function () {
            if (!$scope.param.openBidDate) {
                Util.Toast("请选择开标时间");
                return;
            }
            if (!$scope.param.province) {
                Util.Toast("请选择开标省份");
                return;
            }
            if (!$scope.param.city) {
                Util.Toast("请选择开标地市");
                return;
            }
            if (!$scope.param.county) {
                Util.Toast("请选择开标区县");
                return;
            }
            if (!$scope.param.bidTypeStr) {
                Util.Toast("请填写投标方式");
                return;
            }
            if (!$scope.param.developers) {
                Util.Toast("请填写建设单位");
                return;
            }
            if (!$scope.param.projectName) {
                Util.Toast("请填写工程名称");
                return;
            }
            if (!($scope.param.projectTypeArr && $scope.param.projectTypeArr.length > 0)) {
                Util.Toast("请填写工程类型");
                return;
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }

        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData(id, function (data) {
                $scope.param = data;
                $scope.param.bidUrl = $scope.param.bidUrl
                    ? $scope.param.bidUrl
                    : "http://";
                $scope.param.projectTypeArr = $scope.param.projectTypeArr ? $scope.param.projectTypeArr : ($scope.param.projectType && $scope.param.projectType.split(",") || [])
                $scope.param.qualityReqArr = $scope.param.qualityReqArr ? scope.param.qualityReqArr : ($scope.param.qualityReq && $scope.param.qualityReq.split(",") || [])
            });
            $scope.getTbType();
            $scope.getZZType();
            $scope.showprojectTypeObj()
        };
        // 初始化
        init();
    });
